package com.yuwj.chinaa.callback;

import android.content.Context;

import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;
import com.yuwj.chinaa.R;
import com.yuwj.chinaa.view.LoadingProgressDialog;

/**
 * 返回String的请求回调
 */

public class OkgoDialogWithStringCallback extends StringCallback {

    private LoadingProgressDialog dialog;

    public OkgoDialogWithStringCallback(Context activity) {
        super();
        initDialog(activity);
    }

    @Override
    public void onStart(Request<String, ? extends Request> request) {
        super.onStart(request);
        if (dialog != null && !dialog.isShowing()) {
            dialog.show();
        }
    }

    @Override
    public void onSuccess(Response<String> response) {

    }

    @Override
    public void onFinish() {
        super.onFinish();
        //网络请求结束后关闭对话框
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }
    }

    private void initDialog(Context activity) {
        dialog = new LoadingProgressDialog(activity, R.style.loading_progress_dialog);
        dialog.setCanceledOnTouchOutside(false);
        dialog.setTitle("正在加载...");
    }

}
